package com.atguigu.eduteacher.service.impl;

import com.atguigu.eduteacher.javabean.EduTeacher;
import com.atguigu.eduteacher.javabean.dto.TeacherQuery;
import com.atguigu.eduteacher.mapper.EduTeacherMapper;
import com.atguigu.eduteacher.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2024-10-10
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper,
        EduTeacher> implements EduTeacherService {


    @Override
    public IPage<EduTeacher> pageTeacherConditions(Page<EduTeacher> pageParam
            , TeacherQuery teacherQuery) {

        LambdaQueryWrapper<EduTeacher> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(EduTeacher::getSort);

        if (teacherQuery == null) {
            return baseMapper.selectPage(pageParam, null);
        }
        String name = teacherQuery.getName();
        Integer level = teacherQuery.getLevel();
        String begin = teacherQuery.getBegin();
        String end = teacherQuery.getEnd();
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(EduTeacher::getName, name);
        }
        if (!StringUtils.isEmpty(level)) {
            wrapper.eq(EduTeacher::getLevel, level);
        }
        if (!StringUtils.isEmpty(begin)) {
            wrapper.ge(EduTeacher::getGmtCreate, begin);
        }
        if (!StringUtils.isEmpty(end)) {
            wrapper.le(EduTeacher::getGmtCreate, end);
        }

        wrapper.orderByDesc(EduTeacher::getGmtCreate);

        IPage<EduTeacher> teachers = baseMapper.selectPage(pageParam, wrapper);

        return teachers;
    }
}
